{
 "cells": [
  {
   "cell_type": "code",
   "execution_count": 8,
   "metadata": {},
   "outputs": [],
   "source": [
    "import influxdb\n",
    "import pandas as pd\n",
    "import dateutil.parser as dtparser\n",
    "import datetime\n",
    "import os\n",
    "import numpy as np\n",
    "import random\n",
    "from tqdm import tqdm\n",
    "import matplotlib.pyplot as plt\n",
    "from sklearn.decomposition import PCA\n",
    "from sklearn.metrics import r2_score\n",
    "#client = influxdb.DataFrameClient(host='192.168.38.176', port='8086', username='root', password='root', database='')\n",
    "#client = influxdb.DataFrameClient(host='192.168.38.2', port='8086', username='root', password='root', database='')\n",
    "client = influxdb.DataFrameClient(host='localhost', port=8086, username='root', password='', database='')"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 6,
   "metadata": {},
   "outputs": [],
   "source": [
    "import sys\n",
    "sys.path.append('../../')\n",
    "import redis\n",
    "from Config.myConstant import *\n",
    "from Config.myConfig import *\n",
    "from Config.myFeaturesConstant import *\n",
    "from DataAccess.IndexComponentDataProcess import *\n",
    "from DataAccess.KLineDataProcess import *\n",
    "from DataAccess.TradedayDataProcess import *\n",
    "from DataAccess.IndustryClassification import *\n",
    "from DataAccess.IndexCode import *\n",
    "from DataAccess.StockSharesProcess import *\n",
    "from DataAccess.TickDataProcess import *\n",
    "from DataAccess.TickTransactionDataProcess import TickTransactionDataProcess\n",
    "from DataPrepare.dataPrepareByIndex import *\n",
    "from DataPrepare.dailyKLineDataPrepared import *\n",
    "from Strategy.stockReverseMovement import *\n",
    "from Strategy.myRandomForestForCeiling import *\n",
    "from Strategy.stockReverseByStd import *\n",
    "from Strategy.myAnalysisForReverseByStd import *\n",
    "from Strategy.stockMomentumByStd import *\n",
    "from Strategy.myAnalysisForMomentumByStd import *\n",
    "from Strategy.stockReverseByStdOnTick import *\n",
    "from Strategy.myAnalysisForReverseByTick import myAnalysisForReverseByTick\n",
    "from Strategy.myAnalysisForFactorsByDate import myAnalysisForFactorsByDate\n",
    "from DataPrepare.dailyFactorsProcess import *\n",
    "from DataPrepare.tickFactorsProcess import *\n",
    "from Strategy.stockIntradayByTick.reverse.strategy1 import strategy1\n",
    "from Strategy.stockIntradayByTick.momentum.strategy1 import strategyBreak\n",
    "\n",
    "from Strategy.baseStrategy.grade.gradeStrategy1 import gradeStrategy1\n",
    "from Strategy.baseStrategy.grade.gradeStrategyXgboost import gradeStrategyXgboost\n",
    "from Strategy.baseStrategy.grade.gradeStrategyDNN import gradeStrategyDNN\n",
    "from Strategy.baseStrategy.grade.gradeStrategyCNN import gradeStrategyCNN\n",
    "from Strategy.baseStrategy.grade.gradeStrategyCNNgroups import gradeStrategyCNNgroups\n",
    "from Strategy.baseStrategy.grade.gradeStrategyCNNparameters import gradeStrategyCNNparameters\n",
    "from Strategy.baseStrategy.grade.CnnParameters2 import CnnParameters2\n",
    "from Strategy.baseStrategy.grade.strategy20191112 import strategy20191112\n",
    "from Strategy.baseStrategy.grade.strategy20191115 import strategy20191115\n",
    "from Strategy.baseStrategy.grade.strategy20191115 import strategy20191115\n",
    "from Strategy.baseStrategy.grade.strategy20191202 import strategy20191202\n",
    "from Strategy.baseStrategy.grade.strategy20191224 import strategy20191224\n",
    "from Strategy.baseStrategy.grade.strategy20191228 import strategy20191228\n",
    "from Strategy.baseStrategy.grade.strategy20200110 import strategy20200110\n",
    "from Strategy.baseStrategy.grade.strategy20200123 import strategy20200123\n",
    "from Strategy.baseStrategy.grade.strategy20200315 import strategy20200315\n",
    "from Strategy.baseStrategy.strategyAnalysis import strategyAnalysis\n",
    "from Strategy.baseStrategy.grade.gradeStrategyTWAP import gradeStrategyTWAP\n",
    "\n",
    "from DataPrepare.tickFactors.tickDataPrepared import tickDataPrepared\n",
    "from DataAccess.MinuteKLineProcess import MinuteKLineProcess\n",
    "from DataAccess.DailyKLineProcess import DailyKLineProcess\n",
    "from DataPrepare.dailyFactorsWithInfluxdb.dailyDataPrepared import dailyDataPrepared\n",
    "#from alphaBackTest.backTest import backTest\n",
    "#from alphaBackTest.IndexFullReplication import IndexFullReplication \n",
    "#from T0DataCheck.dataCheck import dataCheck\n",
    "from Utility.mytest import *\n",
    "from Utility.JobLibUtility import *\n",
    "from Utility.UpdateBasicData import *\n",
    "import os\n",
    "os.environ['NLS_LANG'] = 'SIMPLIFIED CHINESE_CHINA.UTF8'\n",
    "os.environ['NUMEXPR_MAX_THREADS'] = '16'\n",
    "import warnings\n",
    "import time\n",
    "from sklearn.metrics import r2_score, mean_squared_error\n",
    "import matplotlib.pyplot as plt\n",
    "import seaborn as sns\n",
    "import numpy as np\n",
    "#from MachineLearning.RNN.RNN001 import RNN001\n",
    "#from MachineLearning.XGBoost.xgboost001 import xgboost001\n",
    "#from MachineLearning.CNN.predictPerformance import predictPerformance"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 9,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "'1.8.9'"
      ]
     },
     "execution_count": 9,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "client.ping()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 10,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "[{'name': '_internal'}]\n"
     ]
    }
   ],
   "source": [
    "dbs = client.get_list_database()\n",
    "print(dbs)\n",
    "#client.create_database('positiontest')\n",
    "#client.drop_database('MaoTickFactors20200430')"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 11,
   "metadata": {},
   "outputs": [],
   "source": [
    "from DataAccess.TickDataProcess import TickDataProcess\n",
    "from DataAccess.StockIPOInfoProcess import *\n",
    "import pymssql\n",
    "#202103-202212,交易日\n",
    "code='600000.SH'\n",
    "datestart=20211221\n",
    "dateend=20211231\n",
    "\n",
    "t = TickDataProcess()\n",
    "data = t.getTickShotDataFromSql(code,datestart)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 23,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "4767"
      ]
     },
     "execution_count": 23,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "data.shape[0]"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 15,
   "metadata": {},
   "outputs": [],
   "source": [
    "#创建数据库\n",
    "client.create_database('test01')"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 20,
   "metadata": {},
   "outputs": [],
   "source": [
    "#切换至数据库\n",
    "client.switch_database('test01')"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 29,
   "metadata": {},
   "outputs": [],
   "source": [
    "def saveDataFrameDataToInfluxdbWithClient(client,data:pd.DataFrame,database:str,measurement:str,tag:dict,connet=InfluxdbServer):\n",
    "        \n",
    "    dbs = client.get_list_database()\n",
    "    if ({'name':database} in dbs)==False:\n",
    "        client.create_database(database)\n",
    "    success=False\n",
    "    myerror=''\n",
    "    for i in range(10):\n",
    "        try:\n",
    "            client.write_points(dataframe=data,\n",
    "                    database=database,\n",
    "                    measurement=measurement,\n",
    "                    tags=tag,\n",
    "                    field_columns=list(data.columns),\n",
    "                    protocol='line',\n",
    "                    batch_size=10000)\n",
    "            success=True\n",
    "            break\n",
    "        except Exception as excp:\n",
    "            myerror=excp\n",
    "            pass\n",
    "    if success==False:\n",
    "        logger.error(f'save data to influxdb {measurement} in {tag} error! {myerror}')\n",
    "    pass"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 31,
   "metadata": {},
   "outputs": [],
   "source": [
    "#from Utility.InfluxdbUtility import *\n",
    "#insert measurements_test01,data.shape[0]\n",
    "#存数据\n",
    "#sdata = InfluxdbUtility()\n",
    "saveDataFrameDataToInfluxdbWithClient(client,data,'test01','m-test01',{})\n",
    "#取数据\n",
    "#getDataFromInfluxdb"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "for i in range(10):\n",
    "    try:\n",
    "        client.write_points(dataframe=data,\n",
    "            database='test01',\n",
    "            measurement='table01',\n",
    "            tags=tag,\n",
    "            field_columns=list(data.columns),\n",
    "            protocol='line',\n",
    "            batch_size=10000)\n",
    "        success=True\n",
    "        break\n",
    "    except Exception as excp:\n",
    "        myerror=excp\n",
    "        pass"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 19,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "[{'name': '_internal'}, {'name': 'test01'}]\n",
      "Help on method write_points in module influxdb._dataframe_client:\n",
      "\n",
      "write_points(dataframe, measurement, tags=None, tag_columns=None, field_columns=None, time_precision=None, database=None, retention_policy=None, batch_size=None, protocol='line', numeric_precision=None) method of influxdb._dataframe_client.DataFrameClient instance\n",
      "    Write to multiple time series names.\n",
      "    \n",
      "    :param dataframe: data points in a DataFrame\n",
      "    :param measurement: name of measurement\n",
      "    :param tags: dictionary of tags, with string key-values\n",
      "    :param tag_columns: [Optional, default None] List of data tag names\n",
      "    :param field_columns: [Options, default None] List of data field names\n",
      "    :param time_precision: [Optional, default None] Either 's', 'ms', 'u'\n",
      "        or 'n'.\n",
      "    :param batch_size: [Optional] Value to write the points in batches\n",
      "        instead of all at one time. Useful for when doing data dumps from\n",
      "        one database to another or when doing a massive write operation\n",
      "    :type batch_size: int\n",
      "    :param protocol: Protocol for writing data. Either 'line' or 'json'.\n",
      "    :param numeric_precision: Precision for floating point values.\n",
      "        Either None, 'full' or some int, where int is the desired decimal\n",
      "        precision. 'full' preserves full precision for int and float\n",
      "        datatypes. Defaults to None, which preserves 14-15 significant\n",
      "        figures for float and all significant figures for int datatypes.\n",
      "\n",
      "None\n"
     ]
    },
    {
     "ename": "TypeError",
     "evalue": "write_points() missing 1 required positional argument: 'measurement'",
     "output_type": "error",
     "traceback": [
      "\u001b[1;31m---------------------------------------------------------------------------\u001b[0m",
      "\u001b[1;31mTypeError\u001b[0m                                 Traceback (most recent call last)",
      "\u001b[1;32m<ipython-input-19-6b2cd2ce2270>\u001b[0m in \u001b[0;36m<module>\u001b[1;34m\u001b[0m\n\u001b[0;32m      2\u001b[0m \u001b[0mprint\u001b[0m\u001b[1;33m(\u001b[0m\u001b[0mdbs\u001b[0m\u001b[1;33m)\u001b[0m\u001b[1;33m\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[0;32m      3\u001b[0m \u001b[0mprint\u001b[0m\u001b[1;33m(\u001b[0m\u001b[0mhelp\u001b[0m\u001b[1;33m(\u001b[0m\u001b[0mclient\u001b[0m\u001b[1;33m.\u001b[0m\u001b[0mwrite_points\u001b[0m\u001b[1;33m)\u001b[0m\u001b[1;33m)\u001b[0m\u001b[1;33m\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[1;32m----> 4\u001b[1;33m \u001b[0mclient\u001b[0m\u001b[1;33m.\u001b[0m\u001b[0mwrite_points\u001b[0m\u001b[1;33m(\u001b[0m\u001b[0mdata\u001b[0m\u001b[1;33m,\u001b[0m\u001b[0mdatabase\u001b[0m \u001b[1;33m=\u001b[0m \u001b[1;34m'test01'\u001b[0m\u001b[1;33m)\u001b[0m\u001b[1;33m\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[0m",
      "\u001b[1;31mTypeError\u001b[0m: write_points() missing 1 required positional argument: 'measurement'"
     ]
    }
   ],
   "source": [
    "dbs = client.get_list_database()\n",
    "print(dbs)\n",
    "print(help(client.write_points))\n",
    "client.write_points(data,tag_columns=[], field_columns=[], database = 'test01')"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "# database='DailyData_Gus'\n",
    "# measure='marketData'\n",
    "# #measure='test'\n",
    "# date=20200101\n",
    "# b = dtparser.parse(str(date))+ datetime.timedelta(hours=0)\n",
    "# e = dtparser.parse(str(date)) + datetime.timedelta(hours=240)\n",
    "# query=f\"\"\" select * from \"{database}\".\"autogen\".\"{measure}\" where time >= {int(b.timestamp() * 1000 * 1000 * 1000)} and time < {int(e.timestamp() * 1000 * 1000* 1000)} \"\"\"\n",
    "# #query=f\"\"\" select * from \"{database}\" \"\"\"\n",
    "# #query=f\"\"\"SELECT * FROM \\\"cpptest\\\".\\\"autogen\\\".\\\"601318.SH\\\"  where time >= '2019-09-24T09:00:00Z' and time < '2019-09-24T16:00:00Z' order by time \"\"\"\n",
    "# #query=f\"\"\"SELECT \\\"stkcd\\\",  \\\"cp\\\", \\\"OPNPRC\\\",\\\"PRECLOSE\\\", \\\"HighLimit\\\",\\\"LowLimit\\\",\\\"hp\\\",\\\"lp\\\",\\\"ts\\\",\\\"tt\\\", \\\"B1\\\",\\\"B2\\\",\\\"B3\\\",\\\"B4\\\",\\\"B5\\\",\\\"B6\\\",\\\"B7\\\",\\\"B8\\\",\\\"B9\\\",\\\"B10\\\",\\\"BV1\\\",\\\"BV2\\\",\\\"BV3\\\",\\\"BV4\\\",\\\"BV5\\\",\\\"BV6\\\",\\\"BV7\\\",\\\"BV8\\\",\\\"BV9\\\",\\\"BV10\\\",\\\"S1\\\", \\\"S2\\\",\\\"S3\\\",\\\"S4\\\",\\\"S5\\\",\\\"S6\\\",\\\"S7\\\",\\\"S8\\\",\\\"S9\\\",\\\"S10\\\",\\\"SV1\\\",\\\"SV2\\\",\\\"SV3\\\",\\\"SV4\\\",\\\"SV5\\\",\\\"SV6\\\",\\\"SV7\\\",\\\"SV8\\\",\\\"SV9\\\" ,\\\"SV10\\\" FROM \\\"cpptest\\\".\\\"autogen\\\".\\\"{measure}\\\"  where time >= '2019-09-24T09:00:00Z' and time < '2019-09-24T16:00:00Z' order by time \"\"\"\n",
    "                         \n",
    "# result=client.query(query)\n",
    "# if result!={}:\n",
    "#     data=pd.DataFrame(result[measure])\n",
    "# else:\n",
    "#     data=pd.DataFrame()\n",
    "# data1=data\n",
    "# data.shape"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "startDate=20100101\n",
    "endDate=20200331\n",
    "\n",
    "days=list(TradedayDataProcess.getTradedays(startDate, endDate))\n",
    "mydays=days[::20]"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "for i in range(len(mydays)-1):\n",
    "    date1=mydays[i]\n",
    "    date2=mydays[i+1]\n",
    "    print(f\"{date1}-{date2}\")"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "database='DailyFactors_Gus'\n",
    "mlist=['BP','EP','Momentum','ROE','Size','Turnover']\n",
    "\n",
    "for i in range(len(mydays)-1):\n",
    "    date1=mydays[i]\n",
    "    date2=mydays[i+1]\n",
    "    myhours=24\n",
    "    database='DailyData_Gus'\n",
    "    measure='marketData'\n",
    "    b = dtparser.parse(str(date1))+ datetime.timedelta(hours=0)\n",
    "    e = dtparser.parse(str(date2)) + datetime.timedelta(hours=myhours)\n",
    "    query=f\"\"\" select * from \"{database}\".\"autogen\".\"{measure}\" where time >= {int(b.timestamp() * 1000 * 1000 * 1000)} and time < {int(e.timestamp() * 1000 * 1000* 1000)} \"\"\"\n",
    "    result=client.query(query)\n",
    "    if result!={}:\n",
    "        data=pd.DataFrame(result[measure])\n",
    "    else:\n",
    "        data=pd.DataFrame()\n",
    "    total=data\n",
    "    if total.shape[0]==0:\n",
    "        cotinue\n",
    "    total.index.names = ['date']\n",
    "    total.reset_index()\n",
    "    \n",
    "    database='DailyFactors_Gus'\n",
    "    for measure in mlist:\n",
    "        b = dtparser.parse(str(date1))+ datetime.timedelta(hours=0)\n",
    "        e = dtparser.parse(str(date2)) + datetime.timedelta(hours=myhours)\n",
    "        query=f\"\"\" select * from \"{database}\".\"autogen\".\"{measure}\" where time >= {int(b.timestamp() * 1000 * 1000 * 1000)} and time < {int(e.timestamp() * 1000 * 1000* 1000)} \"\"\"\n",
    "        #query=f\"\"\" select * from \"{database}\" \"\"\"\n",
    "        #query=f\"\"\"SELECT * FROM \\\"cpptest\\\".\\\"autogen\\\".\\\"601318.SH\\\"  where time >= '2019-09-24T09:00:00Z' and time < '2019-09-24T16:00:00Z' order by time \"\"\"\n",
    "        #query=f\"\"\"SELECT \\\"stkcd\\\",  \\\"cp\\\", \\\"OPNPRC\\\",\\\"PRECLOSE\\\", \\\"HighLimit\\\",\\\"LowLimit\\\",\\\"hp\\\",\\\"lp\\\",\\\"ts\\\",\\\"tt\\\", \\\"B1\\\",\\\"B2\\\",\\\"B3\\\",\\\"B4\\\",\\\"B5\\\",\\\"B6\\\",\\\"B7\\\",\\\"B8\\\",\\\"B9\\\",\\\"B10\\\",\\\"BV1\\\",\\\"BV2\\\",\\\"BV3\\\",\\\"BV4\\\",\\\"BV5\\\",\\\"BV6\\\",\\\"BV7\\\",\\\"BV8\\\",\\\"BV9\\\",\\\"BV10\\\",\\\"S1\\\", \\\"S2\\\",\\\"S3\\\",\\\"S4\\\",\\\"S5\\\",\\\"S6\\\",\\\"S7\\\",\\\"S8\\\",\\\"S9\\\",\\\"S10\\\",\\\"SV1\\\",\\\"SV2\\\",\\\"SV3\\\",\\\"SV4\\\",\\\"SV5\\\",\\\"SV6\\\",\\\"SV7\\\",\\\"SV8\\\",\\\"SV9\\\" ,\\\"SV10\\\" FROM \\\"cpptest\\\".\\\"autogen\\\".\\\"{measure}\\\"  where time >= '2019-09-24T09:00:00Z' and time < '2019-09-24T16:00:00Z' order by time \"\"\"\n",
    "\n",
    "        result=client.query(query)\n",
    "        if result!={}:\n",
    "            data=pd.DataFrame(result[measure])\n",
    "        else:\n",
    "            data=pd.DataFrame()\n",
    "        if data.shape[0]==0:\n",
    "            continue\n",
    "        data.index.names = ['date']\n",
    "        data.reset_index()    \n",
    "        #print(data.columns)\n",
    "        total=pd.merge(total,data,how='outer',on=['code','date'])   \n",
    "    print(f\"data{total.shape} of date {date1}-{date2} complete\")\n",
    "    if (total.shape[0]>0):\n",
    "        total['isST']=total['isST'].fillna(method='ffill')\n",
    "        filename=os.path.join(LocalFileAddress,'dailyFactors',str(date1)+'_'+str(date2)+'.h5')\n",
    "        with pd.HDFStore(filename,'a',complib='blosc:zstd',append=False,complevel=9) as store:\n",
    "            store.append('data',total,append=False,format=\"table\",data_columns=total.columns)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "total.iloc[0]\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "data=total\n",
    "#data=data.drop(columns=['isST'])\n",
    "data.shape\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": []
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "filename=os.path.join('dailyMarketData.h5')\n",
    "with pd.HDFStore(filename,'r',complib='blosc:zstd',append=False,complevel=9) as store:\n",
    "    mydata=store['data']"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "mydata.iloc[0]"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 9,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "(5099, 61)"
      ]
     },
     "execution_count": 9,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "database='MaoTickData20200511'\n",
    "measure='000008.SZ'\n",
    "#measure='test'\n",
    "date=20190102\n",
    "b = dtparser.parse(str(date))+ datetime.timedelta(hours=0)\n",
    "e = dtparser.parse(str(date)) + datetime.timedelta(hours=24)\n",
    "query=f\"\"\" select * from \"{database}\".\"autogen\".\"{measure}\" where time >= {int(b.timestamp() * 1000 * 1000 * 1000)} and time < {int(e.timestamp() * 1000 * 1000* 1000)} \"\"\"\n",
    "#query=f\"\"\" select * from \"{database}\" \"\"\"\n",
    "#query=f\"\"\"SELECT * FROM \\\"cpptest\\\".\\\"autogen\\\".\\\"601318.SH\\\"  where time >= '2019-09-24T09:00:00Z' and time < '2019-09-24T16:00:00Z' order by time \"\"\"\n",
    "#query=f\"\"\"SELECT \\\"stkcd\\\",  \\\"cp\\\", \\\"OPNPRC\\\",\\\"PRECLOSE\\\", \\\"HighLimit\\\",\\\"LowLimit\\\",\\\"hp\\\",\\\"lp\\\",\\\"ts\\\",\\\"tt\\\", \\\"B1\\\",\\\"B2\\\",\\\"B3\\\",\\\"B4\\\",\\\"B5\\\",\\\"B6\\\",\\\"B7\\\",\\\"B8\\\",\\\"B9\\\",\\\"B10\\\",\\\"BV1\\\",\\\"BV2\\\",\\\"BV3\\\",\\\"BV4\\\",\\\"BV5\\\",\\\"BV6\\\",\\\"BV7\\\",\\\"BV8\\\",\\\"BV9\\\",\\\"BV10\\\",\\\"S1\\\", \\\"S2\\\",\\\"S3\\\",\\\"S4\\\",\\\"S5\\\",\\\"S6\\\",\\\"S7\\\",\\\"S8\\\",\\\"S9\\\",\\\"S10\\\",\\\"SV1\\\",\\\"SV2\\\",\\\"SV3\\\",\\\"SV4\\\",\\\"SV5\\\",\\\"SV6\\\",\\\"SV7\\\",\\\"SV8\\\",\\\"SV9\\\" ,\\\"SV10\\\" FROM \\\"cpptest\\\".\\\"autogen\\\".\\\"{measure}\\\"  where time >= '2019-09-24T09:00:00Z' and time < '2019-09-24T16:00:00Z' order by time \"\"\"\n",
    "                         \n",
    "result=client.query(query)\n",
    "if result!={}:\n",
    "    data=pd.DataFrame(result[measure])\n",
    "else:\n",
    "    data=pd.DataFrame()\n",
    "data.shape"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 11,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "B1                         3.88\n",
       "B10                        3.79\n",
       "B2                         3.87\n",
       "B3                         3.86\n",
       "B4                         3.85\n",
       "B5                         3.84\n",
       "B6                         3.83\n",
       "B7                         3.82\n",
       "B8                         3.81\n",
       "B9                          3.8\n",
       "BV1                      119200\n",
       "BV10                      66600\n",
       "BV2                       63687\n",
       "BV3                      149300\n",
       "BV4                      234600\n",
       "BV5                      346600\n",
       "BV6                      113800\n",
       "BV7                      107200\n",
       "BV8                      412400\n",
       "BV9                      525400\n",
       "S1                         3.89\n",
       "S10                        3.98\n",
       "S2                          3.9\n",
       "S3                         3.91\n",
       "S4                         3.92\n",
       "S5                         3.93\n",
       "S6                         3.94\n",
       "S7                         3.95\n",
       "S8                         3.96\n",
       "S9                         3.97\n",
       "                        ...    \n",
       "SV10                      88700\n",
       "SV2                      551100\n",
       "SV3                      184700\n",
       "SV4                      105833\n",
       "SV5                       20600\n",
       "SV6                       48800\n",
       "SV7                      184100\n",
       "SV8                      116300\n",
       "SV9                       48000\n",
       "amount                 18196566\n",
       "amountIncrease                0\n",
       "code                  000008.SZ\n",
       "dailyOpen                  3.89\n",
       "dailyPreClose              3.89\n",
       "date                   20190102\n",
       "highLimit                  4.28\n",
       "lastPrice                  3.88\n",
       "localRecordTime       105603143\n",
       "lowLimit                    3.5\n",
       "midPrice                  3.885\n",
       "realData                      1\n",
       "tick                  105500000\n",
       "total_ask_size          4713389\n",
       "total_bid_size          2671787\n",
       "tradeStatus                 2  \n",
       "transactions_count         2165\n",
       "volume                  4695513\n",
       "volumeIncrease                0\n",
       "weightedAvgAsk             4.08\n",
       "weightedAvgBid             3.79\n",
       "Name: 2019-01-02 10:55:00+00:00, Length: 61, dtype: object"
      ]
     },
     "execution_count": 11,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "data.iloc[2000]"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "data['buySlip']=data['S1'].rolling(3).min().shift(-3)-data['S1']\n",
    "data['sellSlip']=-data['B1'].rolling(3).max().shift(-3)+data['B1']"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "data[['S1','buySlip','B1','sellSlip']]"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 8,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "(4491, 146)"
      ]
     },
     "execution_count": 8,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "database='MaoTickFactors20191118'\n",
    "database='MaoTickFactors20200430'\n",
    "measure='000008.SZ'\n",
    "measure='601899.SH'\n",
    "date=20190102\n",
    "date2=date\n",
    "b = dtparser.parse(str(date))+ datetime.timedelta(hours=0)\n",
    "e = dtparser.parse(str(date2)) + datetime.timedelta(hours=24)\n",
    "query=f\"\"\" select * from \"{database}\".\"autogen\".\"{measure}\" where time >= {int(b.timestamp() * 1000 * 1000 * 1000)} and time < {int(e.timestamp() * 1000 * 1000* 1000)} \"\"\"\n",
    "#query=f\"\"\" select * from \"{database}\" \"\"\"\n",
    "#query=f\"\"\"SELECT * FROM \\\"cpptest\\\".\\\"autogen\\\".\\\"601318.SH\\\"  where time >= '2019-09-24T09:00:00Z' and time < '2019-09-24T16:00:00Z' order by time \"\"\"\n",
    "#query=f\"\"\"SELECT \\\"stkcd\\\",  \\\"cp\\\", \\\"OPNPRC\\\",\\\"PRECLOSE\\\", \\\"HighLimit\\\",\\\"LowLimit\\\",\\\"hp\\\",\\\"lp\\\",\\\"ts\\\",\\\"tt\\\", \\\"B1\\\",\\\"B2\\\",\\\"B3\\\",\\\"B4\\\",\\\"B5\\\",\\\"B6\\\",\\\"B7\\\",\\\"B8\\\",\\\"B9\\\",\\\"B10\\\",\\\"BV1\\\",\\\"BV2\\\",\\\"BV3\\\",\\\"BV4\\\",\\\"BV5\\\",\\\"BV6\\\",\\\"BV7\\\",\\\"BV8\\\",\\\"BV9\\\",\\\"BV10\\\",\\\"S1\\\", \\\"S2\\\",\\\"S3\\\",\\\"S4\\\",\\\"S5\\\",\\\"S6\\\",\\\"S7\\\",\\\"S8\\\",\\\"S9\\\",\\\"S10\\\",\\\"SV1\\\",\\\"SV2\\\",\\\"SV3\\\",\\\"SV4\\\",\\\"SV5\\\",\\\"SV6\\\",\\\"SV7\\\",\\\"SV8\\\",\\\"SV9\\\" ,\\\"SV10\\\" FROM \\\"cpptest\\\".\\\"autogen\\\".\\\"{measure}\\\"  where time >= '2019-09-24T09:00:00Z' and time < '2019-09-24T16:00:00Z' order by time \"\"\"\n",
    "                         \n",
    "result=client.query(query)\n",
    "if result!={}:\n",
    "    data=pd.DataFrame(result[measure])\n",
    "else:\n",
    "    data=pd.DataFrame()\n",
    "data.shape\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": []
  },
  {
   "cell_type": "code",
   "execution_count": 14,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>B1</th>\n",
       "      <th>BV1</th>\n",
       "      <th>EMABuyForce15</th>\n",
       "      <th>EMABuySellAmountWeightedPressure1_10_80</th>\n",
       "      <th>EMABuySellPress1_10</th>\n",
       "      <th>EMABuySellVolumeWeightedPressure1_10_80</th>\n",
       "      <th>EMASellForce15</th>\n",
       "      <th>S1</th>\n",
       "      <th>SV1</th>\n",
       "      <th>activeBuying</th>\n",
       "      <th>...</th>\n",
       "      <th>vwap15sTo5m</th>\n",
       "      <th>vwap15sToBV10m</th>\n",
       "      <th>vwap15sToBV30m</th>\n",
       "      <th>vwap15sToVwap</th>\n",
       "      <th>vwap1Tick</th>\n",
       "      <th>vwap1m</th>\n",
       "      <th>vwap2m</th>\n",
       "      <th>vwap30m</th>\n",
       "      <th>vwap5m</th>\n",
       "      <th>vwapToday</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "  </tbody>\n",
       "</table>\n",
       "<p>0 rows × 143 columns</p>\n",
       "</div>"
      ],
      "text/plain": [
       "Empty DataFrame\n",
       "Columns: [B1, BV1, EMABuyForce15, EMABuySellAmountWeightedPressure1_10_80, EMABuySellPress1_10, EMABuySellVolumeWeightedPressure1_10_80, EMASellForce15, S1, SV1, activeBuying, activeBuyingAmount, activeBuyingAmountTotal10m, activeBuyingAmountTotal2m, activeBuyingAmountTotal30m, activeBuyingAmountTotal5m, activeBuyingIncrease, activeBuyingIncreaseMean10m, activeBuyingIncreaseMean2m, activeBuyingIncreaseMean30m, activeBuyingIncreaseMean5m, activeBuyingSellingAmountRatio10m, activeBuyingSellingAmountRatio2m, activeBuyingSellingAmountRatio30m, activeBuyingSellingAmountRatio5m, activeSelling, activeSellingAmount, activeSellingAmountTotal10m, activeSellingAmountTotal2m, activeSellingAmountTotal30m, activeSellingAmountTotal5m, activeSellingDecrease, activeSellingDecreaseMean10m, activeSellingDecreaseMean2m, activeSellingDecreaseMean30m, activeSellingDecreaseMean5m, amount1Tick, buyAverageAmountWeighted1_10_80, buyAverageVolume1_10, buyAverageVolumeWeighted1_10_80, buyForce, buySellAmountWeightedPressure1_10_80, buySellForceChange, buySellPress1_10, buySellSpread, buySellVolumeRatio10, buySellVolumeRatio2, buySellVolumeRatio5, buySellVolumeWeightedPressure1_10_80, buySellVwap10Spread, buySellVwap2Spread, buySellVwap5Spread, buySellWeightedVolumeRatio10, buySellWeightedVolumeRatio2, buySellWeightedVolumeRatio5, buyVolume10, buyVolume2, buyVolume5, buyVwap1, buyVwap10, buyVwap2, buyVwap5, buyWeightedVolume10, buyWeightedVolume2, buyWeightedVolume5, code, date, differenceHighLow10m, differenceHighLow30m, increaseToday, logbuySellSpread, logbuySellVwap10Spread, logbuySellVwap2Spread, logbuySellVwap5Spread, maxVwap15sPrice10m, maxVwap15sPrice30m, midInBuySellVwap1, midInBuySellVwap10, midInBuySellVwap2, midInBuySellVwap5, midIncreaseNext10m, midPrice, minVwap15sPrice10m, minVwap15sPrice30m, openToPreClose, realData, sellAverageAmountWeighted1_10_80, sellAverageVolume1_10, sellAverageVolumeWeighted1_10_80, sellForce, sellVolume10, sellVolume2, sellVolume5, sellVwap1, sellVwap10, sellVwap2, sellVwap5, sellWeightedVolume10, sellWeightedVolume2, sellWeightedVolume5, tick, ...]\n",
       "Index: []\n",
       "\n",
       "[0 rows x 143 columns]"
      ]
     },
     "execution_count": 14,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "errorData=data[data.isna().sum(axis=1)>0]\n",
    "errorData\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 7,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "B1                                                3.9\n",
       "BV1                                             36300\n",
       "EMABuyForce15                                 8.04171\n",
       "EMABuySellAmountWeightedPressure1_10_80     -0.136383\n",
       "EMABuySellPress1_10                         -0.251799\n",
       "EMABuySellVolumeWeightedPressure1_10_80     -0.258267\n",
       "EMASellForce15                                8.36222\n",
       "S1                                               3.91\n",
       "SV1                                            125300\n",
       "activeBuying                                        1\n",
       "activeBuyingAmount                              17595\n",
       "activeBuyingAmountTotal10m                     182388\n",
       "activeBuyingAmountTotal2m                      182388\n",
       "activeBuyingAmountTotal30m                     182388\n",
       "activeBuyingAmountTotal5m                      182388\n",
       "activeBuyingIncrease                       0.00128041\n",
       "activeBuyingIncreaseMean10m                0.00064627\n",
       "activeBuyingIncreaseMean2m                 0.00064627\n",
       "activeBuyingIncreaseMean30m                0.00064627\n",
       "activeBuyingIncreaseMean5m                 0.00064627\n",
       "activeBuyingSellingAmountRatio10m            0.642625\n",
       "activeBuyingSellingAmountRatio2m             0.642625\n",
       "activeBuyingSellingAmountRatio30m            0.642625\n",
       "activeBuyingSellingAmountRatio5m             0.642625\n",
       "activeSelling                                       0\n",
       "activeSellingAmount                                 0\n",
       "activeSellingAmountTotal10m                    101429\n",
       "activeSellingAmountTotal2m                     101429\n",
       "activeSellingAmountTotal30m                    101429\n",
       "activeSellingAmountTotal5m                     101429\n",
       "activeSellingDecrease                               0\n",
       "activeSellingDecreaseMean10m              -0.00116928\n",
       "activeSellingDecreaseMean2m               -0.00116928\n",
       "activeSellingDecreaseMean30m              -0.00116928\n",
       "activeSellingDecreaseMean5m               -0.00116928\n",
       "amount1Tick                                     17595\n",
       "buyAverageAmountWeighted1_10_80               11.2567\n",
       "buyAverageVolume1_10                          10.6368\n",
       "buyAverageVolumeWeighted1_10_80               9.90265\n",
       "buyForce                                      9.53021\n",
       "buySellAmountWeightedPressure1_10_80         -0.14427\n",
       "buySellForceChange                           -0.32051\n",
       "buySellPress1_10                            -0.317755\n",
       "buySellSpread                              0.00256082\n",
       "buySellVolumeRatio10                         0.421223\n",
       "buySellVolumeRatio2                          0.414403\n",
       "buySellVolumeRatio5                          0.467707\n",
       "buySellVolumeWeightedPressure1_10_80        -0.274977\n",
       "buySellVwap10Spread                         0.0245768\n",
       "buySellVwap2Spread                         0.00435234\n",
       "buySellVwap5Spread                          0.0122337\n",
       "buySellWeightedVolumeRatio10                 0.348323\n",
       "buySellWeightedVolumeRatio2                  0.303918\n",
       "buySellWeightedVolumeRatio5                  0.340801\n",
       "buyVolume10                                    416400\n",
       "buyVolume2                                      96100\n",
       "buyVolume5                                     239700\n",
       "buyVwap1                                          3.9\n",
       "buyVwap10                                     3.86018\n",
       "buyVwap2                                      3.89378\n",
       "buyVwap5                                      3.87869\n",
       "buyWeightedVolume10                           12.0994\n",
       "buyWeightedVolume2                            11.6304\n",
       "buyWeightedVolume5                             11.941\n",
       "code                                        000008.SZ\n",
       "date                                         20190102\n",
       "differenceHighLow10m                       0.00257449\n",
       "differenceHighLow30m                       0.00257449\n",
       "increaseToday                              0.00385604\n",
       "logbuySellSpread                             -5.96353\n",
       "logbuySellVwap10Spread                       -3.70554\n",
       "logbuySellVwap2Spread                        -5.43475\n",
       "logbuySellVwap5Spread                        -4.40274\n",
       "maxVwap15sPrice10m                            3.90505\n",
       "maxVwap15sPrice30m                            3.90505\n",
       "midInBuySellVwap1                                   0\n",
       "midInBuySellVwap10                         -0.0329426\n",
       "midInBuySellVwap2                            0.160318\n",
       "midInBuySellVwap5                           0.0507337\n",
       "midIncreaseNext10m                         -0.0112909\n",
       "midPrice                                        3.905\n",
       "minVwap15sPrice10m                              3.895\n",
       "minVwap15sPrice30m                              3.895\n",
       "openToPreClose                                      0\n",
       "realData                                            1\n",
       "sellAverageAmountWeighted1_10_80              11.5473\n",
       "sellAverageVolume1_10                         10.9546\n",
       "sellAverageVolumeWeighted1_10_80              10.1776\n",
       "sellForce                                           0\n",
       "sellVolume10                                   572150\n",
       "sellVolume2                                    135800\n",
       "sellVolume5                                    272800\n",
       "sellVwap1                                        3.91\n",
       "sellVwap10                                    3.95615\n",
       "sellVwap2                                     3.91077\n",
       "sellVwap5                                     3.92646\n",
       "sellWeightedVolume10                          12.7258\n",
       "sellWeightedVolume2                           12.4591\n",
       "sellWeightedVolume5                           12.6007\n",
       "tick                                        093030000\n",
       "totalVolume10                                  988550\n",
       "volume1tick                                      4500\n",
       "vwap10m                                       3.90395\n",
       "vwap15s                                       3.90267\n",
       "vwap15sBV10m                               0.00044918\n",
       "vwap15sBV30m                               0.00044918\n",
       "vwap15sInOpenAndClose                         12.6715\n",
       "vwap15sInPrevious10m                         0.236471\n",
       "vwap15sInPrevious10mByStd                   -0.835815\n",
       "vwap15sInPrevious30m                         0.236471\n",
       "vwap15sInPrevious30mByStd                   -0.835815\n",
       "vwap15sIncreaseToOpen                      0.00325745\n",
       "vwap15sIncreaseToPreClose                  0.00325745\n",
       "vwap15sPriceIncrease                       0.00036876\n",
       "vwap15sPriceIncreasePrevious10m            0.00196957\n",
       "vwap15sPriceIncreasePrevious1m             0.00196957\n",
       "vwap15sPriceIncreasePrevious2m             0.00196957\n",
       "vwap15sPriceIncreasePrevious30m            0.00196957\n",
       "vwap15sPriceIncreasePrevious5m             0.00196957\n",
       "vwap15sQuantile10m                                0.5\n",
       "vwap15sQuantile2m                                 0.5\n",
       "vwap15sQuantile30m                                0.5\n",
       "vwap15sQuantile5m                                 0.5\n",
       "vwap15sSharpe10m                              0.65111\n",
       "vwap15sSharpe2m                               0.65111\n",
       "vwap15sSharpe30m                              0.65111\n",
       "vwap15sSharpe5m                               0.65111\n",
       "vwap15sStd10m                              0.00019557\n",
       "vwap15sStd30m                              0.00019557\n",
       "vwap15sTo10m                              -0.00032691\n",
       "vwap15sTo1m                               -0.00032691\n",
       "vwap15sTo2m                               -0.00032691\n",
       "vwap15sTo30m                              -0.00032691\n",
       "vwap15sTo5m                               -0.00032691\n",
       "vwap15sToBV10m                                4.38481\n",
       "vwap15sToBV30m                                4.38481\n",
       "vwap15sToVwap                              0.00156544\n",
       "vwap1Tick                                        3.91\n",
       "vwap1m                                        3.90395\n",
       "vwap2m                                        3.90395\n",
       "vwap30m                                       3.90395\n",
       "vwap5m                                        3.90395\n",
       "vwapToday                                     3.89657\n",
       "Name: 2019-01-02 09:30:30+00:00, dtype: object"
      ]
     },
     "execution_count": 7,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "pd.set_option('display.max_rows', 200)\n",
    "data.iloc[10]\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": []
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "client = influxdb.DataFrameClient(host='192.168.58.71', port='8086', username='root', password='root', database='')\n",
    "#client = influxdb.DataFrameClient(host='192.168.38.2', port='8086', username='root', password='root', database='')\n",
    "database='MaoTickPredict1m2m5m8003weeks'\n",
    "database='MaoTickPredict2020New'\n",
    "measure='603883.SH'\n",
    "#measure='test'\n",
    "date=20200401\n",
    "timeStart=time.time()\n",
    "b = dtparser.parse(str(date))+ datetime.timedelta(hours=0)\n",
    "e = dtparser.parse(str(date)) + datetime.timedelta(hours=24000)\n",
    "query=f\"\"\" select * from \"{database}\".\"autogen\".\"{measure}\" where time >= {int(b.timestamp() * 1000 * 1000 * 1000)} and time < {int(e.timestamp() * 1000 * 1000* 1000)} \"\"\"\n",
    "#query=f\"\"\" select * from \"{database}\" \"\"\"\n",
    "#query=f\"\"\"SELECT * FROM \\\"cpptest\\\".\\\"autogen\\\".\\\"601318.SH\\\"  where time >= '2019-09-24T09:00:00Z' and time < '2019-09-24T16:00:00Z' order by time \"\"\"\n",
    "#query=f\"\"\"SELECT \\\"stkcd\\\",  \\\"cp\\\", \\\"OPNPRC\\\",\\\"PRECLOSE\\\", \\\"HighLimit\\\",\\\"LowLimit\\\",\\\"hp\\\",\\\"lp\\\",\\\"ts\\\",\\\"tt\\\", \\\"B1\\\",\\\"B2\\\",\\\"B3\\\",\\\"B4\\\",\\\"B5\\\",\\\"B6\\\",\\\"B7\\\",\\\"B8\\\",\\\"B9\\\",\\\"B10\\\",\\\"BV1\\\",\\\"BV2\\\",\\\"BV3\\\",\\\"BV4\\\",\\\"BV5\\\",\\\"BV6\\\",\\\"BV7\\\",\\\"BV8\\\",\\\"BV9\\\",\\\"BV10\\\",\\\"S1\\\", \\\"S2\\\",\\\"S3\\\",\\\"S4\\\",\\\"S5\\\",\\\"S6\\\",\\\"S7\\\",\\\"S8\\\",\\\"S9\\\",\\\"S10\\\",\\\"SV1\\\",\\\"SV2\\\",\\\"SV3\\\",\\\"SV4\\\",\\\"SV5\\\",\\\"SV6\\\",\\\"SV7\\\",\\\"SV8\\\",\\\"SV9\\\" ,\\\"SV10\\\" FROM \\\"cpptest\\\".\\\"autogen\\\".\\\"{measure}\\\"  where time >= '2019-09-24T09:00:00Z' and time < '2019-09-24T16:00:00Z' order by time \"\"\"\n",
    "                         \n",
    "result=client.query(query)\n",
    "if result!={}:\n",
    "    data=pd.DataFrame(result[measure])\n",
    "else:\n",
    "    data=pd.DataFrame()\n",
    "print(data.shape)\n",
    "timeEnd=time.time()\n",
    "# print(data[['midIncreaseMinNext1m','predictMinNext1m']].corr().iloc[0,1])\n",
    "# print(data[['midIncreaseMaxNext1m','predictMaxNext1m']].corr().iloc[0,1])\n",
    "# print(r2_score(data['midIncreaseMinNext1m'],data['predictMinNext1m']))\n",
    "# print(r2_score(data['midIncreaseMaxNext1m'],data['predictMaxNext1m']))\n",
    "\n",
    "# print(data[data['predictMaxNext1m']>0.2]['midIncreaseMaxNext1m'].mean())\n",
    "# print(data[data['predictMinNext1m']<-0.2]['midIncreaseMinNext1m'].mean())\n",
    "# print(data[data['predictMaxNext1m']>0.2]['predictMaxNext1m'].mean())\n",
    "# print(data[data['predictMinNext1m']<-0.2]['predictMinNext1m'].mean())\n",
    "data['predictMax']=(data['predictMaxNext1m']+data['predictMaxNext2m']+data['predictMaxNext5m'])/3\n",
    "data['predictMin']=(data['predictMinNext1m']+data['predictMinNext2m']+data['predictMinNext5m'])/3\n",
    "data['max']=(data['midIncreaseMaxNext1m']+data['midIncreaseMaxNext2m']+data['midIncreaseMaxNext5m'])/3\n",
    "data['min']=(data['midIncreaseMinNext1m']+data['midIncreaseMinNext2m']+data['midIncreaseMinNext5m'])/3\n",
    "new=data[['predictMax','predictMin','max','min']].astype('float')\n",
    "new['min']=np.round(new['min'],4)\n",
    "new['max']=np.round(new['max'],4)\n",
    "print(abs(new[new['predictMax']>0.3]['predictMax']-new[new['predictMax']>0.3]['max']).mean())\n",
    "print(new[new['predictMax']>0.3]['max'].shape)\n",
    "print(abs(new[new['predictMin']<-0.3]['predictMin']-new[new['predictMin']<-0.3]['min']).mean())\n",
    "print(new[new['predictMin']<-0.3]['min'].shape)\n",
    "print(timeEnd-timeStart)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "print(abs(new[new['predictMax']>0.3]['predictMax']-new[new['predictMax']>0.3]['max']).mean())\n",
    "print(new[new['predictMax']>0.3]['max'].shape)\n",
    "print(abs(new[new['predictMin']<-0.3]['predictMin']-new[new['predictMin']<-0.3]['min']).mean())\n",
    "print(new[new['predictMin']<-0.3]['min'].shape)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "data['predictMax']=(data['predictMaxNext1m']+data['predictMaxNext2m']+data['predictMaxNext5m'])/3\n",
    "data['predictMin']=(data['predictMinNext1m']+data['predictMinNext2m']+data['predictMinNext5m'])/3\n",
    "data['max']=(data['midIncreaseMaxNext1m']+data['midIncreaseMaxNext2m']+data['midIncreaseMaxNext5m'])/3\n",
    "data['min']=(data['midIncreaseMinNext1m']+data['midIncreaseMinNext2m']+data['midIncreaseMinNext5m'])/3\n",
    "new=data[['predictMax','predictMin','max','min']].astype('float')\n",
    "new['min']=np.round(new['min'],4)\n",
    "new['max']=np.round(new['max'],4)\n",
    "print(new[new['max']>0.3]['max'].mean())\n",
    "print(new[new['max']>0.3]['max'].shape)\n",
    "print(new[new['min']<-0.3]['min'].mean())\n",
    "print(new[new['min']<-0.3]['min'].shape)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "data.iloc[203]"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "max(new['max'],new['min'])"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "new[(new['predictMax']>0.2) & (new['predictMin']>-0.05)]"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "new=new.sort_values(['min'])\n",
    "new"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "new[(new['predictMin']<-0.25)]"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "new.iloc[320:400]"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "import matplotlib.pyplot as plt\n",
    "plt.plot(list(new['predictMax']))\n",
    "plt.plot(list(new['max']))\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "plt.plot(list(new['predictMin']))\n",
    "plt.plot(list(new['min']))\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "data.columns"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "data['buySharpeNext5m'].hist(bins=1000)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "data['sellSharpeNext5m'].hist(bins=1000)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "data[data['buySharpeNext5m']>0]['buySharpeNext5m'].median()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "data[data['buySharpeNext5m']>0].shape[0]/data.shape[0]"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "data[data['sellSharpeNext5m']<0].shape[0]/data.shape[0]"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "data[(data['sellSharpeNext5m']<0) & (data['buySharpeNext5m']>0)]\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": []
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "data[['midIncreaseMinNext1m','predictMinNext1m']].corr().iloc[0,1]"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "#client = influxdb.DataFrameClient(host='192.168.58.71', port='8086', username='root', password='root', database='')\n",
    "client = influxdb.DataFrameClient(host='192.168.38.2', port='8086', username='root', password='root', database='')\n",
    "database='MaoTickPredict20190909'\n",
    "measure='600519.SH'\n",
    "#measure='test'\n",
    "date=20190305\n",
    "b = dtparser.parse(str(date))+ datetime.timedelta(hours=0)\n",
    "e = dtparser.parse(str(date)) + datetime.timedelta(hours=24)\n",
    "query=f\"\"\" select * from \"{database}\".\"autogen\".\"{measure}\" where time >= {int(b.timestamp() * 1000 * 1000 * 1000)} and time < {int(e.timestamp() * 1000 * 1000* 1000)} \"\"\"\n",
    "#query=f\"\"\" select * from \"{database}\" \"\"\"\n",
    "#query=f\"\"\"SELECT * FROM \\\"cpptest\\\".\\\"autogen\\\".\\\"601318.SH\\\"  where time >= '2019-09-24T09:00:00Z' and time < '2019-09-24T16:00:00Z' order by time \"\"\"\n",
    "#query=f\"\"\"SELECT \\\"stkcd\\\",  \\\"cp\\\", \\\"OPNPRC\\\",\\\"PRECLOSE\\\", \\\"HighLimit\\\",\\\"LowLimit\\\",\\\"hp\\\",\\\"lp\\\",\\\"ts\\\",\\\"tt\\\", \\\"B1\\\",\\\"B2\\\",\\\"B3\\\",\\\"B4\\\",\\\"B5\\\",\\\"B6\\\",\\\"B7\\\",\\\"B8\\\",\\\"B9\\\",\\\"B10\\\",\\\"BV1\\\",\\\"BV2\\\",\\\"BV3\\\",\\\"BV4\\\",\\\"BV5\\\",\\\"BV6\\\",\\\"BV7\\\",\\\"BV8\\\",\\\"BV9\\\",\\\"BV10\\\",\\\"S1\\\", \\\"S2\\\",\\\"S3\\\",\\\"S4\\\",\\\"S5\\\",\\\"S6\\\",\\\"S7\\\",\\\"S8\\\",\\\"S9\\\",\\\"S10\\\",\\\"SV1\\\",\\\"SV2\\\",\\\"SV3\\\",\\\"SV4\\\",\\\"SV5\\\",\\\"SV6\\\",\\\"SV7\\\",\\\"SV8\\\",\\\"SV9\\\" ,\\\"SV10\\\" FROM \\\"cpptest\\\".\\\"autogen\\\".\\\"{measure}\\\"  where time >= '2019-09-24T09:00:00Z' and time < '2019-09-24T16:00:00Z' order by time \"\"\"\n",
    "                         \n",
    "result=client.query(query)\n",
    "if result!={}:\n",
    "    data=pd.DataFrame(result[measure])\n",
    "else:\n",
    "    data=pd.DataFrame()\n",
    "print(data[['midIncreaseMinNext1m','predictMinNext1m']].corr().iloc[0,1])\n",
    "print(data[['midIncreaseMaxNext1m','predictMaxNext1m']].corr().iloc[0,1])\n",
    "print(r2_score(data['midIncreaseMinNext1m'],data['predictMinNext1m']))\n",
    "print(r2_score(data['midIncreaseMaxNext1m'],data['predictMaxNext1m']))"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "client = influxdb.DataFrameClient(host='192.168.58.71', port='8086', username='root', password='root', database='')\n",
    "#client = influxdb.DataFrameClient(host='192.168.38.2', port='8086', username='root', password='root', database='')\n",
    "#database='MaoTickPredict20190909original'\n",
    "database='MaoTickPredict20190909'\n",
    "measure='000001.SZ'\n",
    "#measure='test'\n",
    "date=20190830\n",
    "date2=20190830\n",
    "b = dtparser.parse(str(date))+ datetime.timedelta(hours=0)\n",
    "e = dtparser.parse(str(date2)) + datetime.timedelta(hours=24)\n",
    "query=f\"\"\" select * from \"{database}\".\"autogen\".\"{measure}\" where time >= {int(b.timestamp() * 1000 * 1000 * 1000)} and time < {int(e.timestamp() * 1000 * 1000* 1000)} \"\"\"\n",
    "#query=f\"\"\" select * from \"{database}\" \"\"\"\n",
    "#query=f\"\"\"SELECT * FROM \\\"cpptest\\\".\\\"autogen\\\".\\\"601318.SH\\\"  where time >= '2019-09-24T09:00:00Z' and time < '2019-09-24T16:00:00Z' order by time \"\"\"\n",
    "#query=f\"\"\"SELECT \\\"stkcd\\\",  \\\"cp\\\", \\\"OPNPRC\\\",\\\"PRECLOSE\\\", \\\"HighLimit\\\",\\\"LowLimit\\\",\\\"hp\\\",\\\"lp\\\",\\\"ts\\\",\\\"tt\\\", \\\"B1\\\",\\\"B2\\\",\\\"B3\\\",\\\"B4\\\",\\\"B5\\\",\\\"B6\\\",\\\"B7\\\",\\\"B8\\\",\\\"B9\\\",\\\"B10\\\",\\\"BV1\\\",\\\"BV2\\\",\\\"BV3\\\",\\\"BV4\\\",\\\"BV5\\\",\\\"BV6\\\",\\\"BV7\\\",\\\"BV8\\\",\\\"BV9\\\",\\\"BV10\\\",\\\"S1\\\", \\\"S2\\\",\\\"S3\\\",\\\"S4\\\",\\\"S5\\\",\\\"S6\\\",\\\"S7\\\",\\\"S8\\\",\\\"S9\\\",\\\"S10\\\",\\\"SV1\\\",\\\"SV2\\\",\\\"SV3\\\",\\\"SV4\\\",\\\"SV5\\\",\\\"SV6\\\",\\\"SV7\\\",\\\"SV8\\\",\\\"SV9\\\" ,\\\"SV10\\\" FROM \\\"cpptest\\\".\\\"autogen\\\".\\\"{measure}\\\"  where time >= '2019-09-24T09:00:00Z' and time < '2019-09-24T16:00:00Z' order by time \"\"\"\n",
    "                         \n",
    "result=client.query(query)\n",
    "if result!={}:\n",
    "    data=pd.DataFrame(result[measure])\n",
    "else:\n",
    "    data=pd.DataFrame()\n",
    "print(data[['midIncreaseMinNext1m','predictMinNext1m']].corr())\n",
    "print(data[['midIncreaseMaxNext1m','predictMaxNext1m']].corr())\n",
    "print(r2_score(data['midIncreaseMinNext1m'],data['predictMinNext1m']))\n",
    "print(r2_score(data['midIncreaseMaxNext1m'],data['predictMaxNext1m']))\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "data.iloc[0]"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "print(r2_score(data[['midIncreaseMaxNext1m','midIncreaseMinNext1m']].values.reshape(-1),data[['predictMaxNext1m','predictMaxNext1m']].values.reshape(-1)))"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "data[['midIncreaseMaxNext1m','midIncreaseMinNext1m']].values.reshape(-1)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "pd.set_option('display.max_rows',5000)\n",
    "data"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "#client = influxdb.DataFrameClient(host='192.168.58.71', port='8086', username='root', password='root', database='')\n",
    "client = influxdb.DataFrameClient(host='192.168.38.2', port='8086', username='root', password='root', database='')\n",
    "database='MaoTickData'\n",
    "measure='600519.SH'\n",
    "#measure='test'\n",
    "date=20191105\n",
    "b = dtparser.parse(str(date))+ datetime.timedelta(hours=0)\n",
    "e = dtparser.parse(str(date)) + datetime.timedelta(hours=24)\n",
    "query=f\"\"\" select * from \"{database}\".\"autogen\".\"{measure}\" where time >= {int(b.timestamp() * 1000 * 1000 * 1000)} and time < {int(e.timestamp() * 1000 * 1000* 1000)} \"\"\"\n",
    "#query=f\"\"\" select * from \"{database}\" \"\"\"\n",
    "#query=f\"\"\"SELECT * FROM \\\"cpptest\\\".\\\"autogen\\\".\\\"601318.SH\\\"  where time >= '2019-09-24T09:00:00Z' and time < '2019-09-24T16:00:00Z' order by time \"\"\"\n",
    "#query=f\"\"\"SELECT \\\"stkcd\\\",  \\\"cp\\\", \\\"OPNPRC\\\",\\\"PRECLOSE\\\", \\\"HighLimit\\\",\\\"LowLimit\\\",\\\"hp\\\",\\\"lp\\\",\\\"ts\\\",\\\"tt\\\", \\\"B1\\\",\\\"B2\\\",\\\"B3\\\",\\\"B4\\\",\\\"B5\\\",\\\"B6\\\",\\\"B7\\\",\\\"B8\\\",\\\"B9\\\",\\\"B10\\\",\\\"BV1\\\",\\\"BV2\\\",\\\"BV3\\\",\\\"BV4\\\",\\\"BV5\\\",\\\"BV6\\\",\\\"BV7\\\",\\\"BV8\\\",\\\"BV9\\\",\\\"BV10\\\",\\\"S1\\\", \\\"S2\\\",\\\"S3\\\",\\\"S4\\\",\\\"S5\\\",\\\"S6\\\",\\\"S7\\\",\\\"S8\\\",\\\"S9\\\",\\\"S10\\\",\\\"SV1\\\",\\\"SV2\\\",\\\"SV3\\\",\\\"SV4\\\",\\\"SV5\\\",\\\"SV6\\\",\\\"SV7\\\",\\\"SV8\\\",\\\"SV9\\\" ,\\\"SV10\\\" FROM \\\"cpptest\\\".\\\"autogen\\\".\\\"{measure}\\\"  where time >= '2019-09-24T09:00:00Z' and time < '2019-09-24T16:00:00Z' order by time \"\"\"\n",
    "                         \n",
    "result=client.query(query)\n",
    "if result!={}:\n",
    "    data=pd.DataFrame(result[measure])\n",
    "else:\n",
    "    data=pd.DataFrame()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": []
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "database='order'\n",
    "#client.drop_database(database)\n",
    "#client.create_database(database)\n",
    "\n",
    "measure='order'\n",
    "#measure='test'\n",
    "date=20200427\n",
    "b = dtparser.parse(str(date))+ datetime.timedelta(hours=6)\n",
    "e = dtparser.parse(str(date)) + datetime.timedelta(hours=24)\n",
    "query=f\"\"\" select * from \"{database}\".\"autogen\".\"{measure}\" where time >= {int(b.timestamp() * 1000 * 1000 * 1000)} and time < {int(e.timestamp() * 1000 * 1000* 1000)} \"\"\"\n",
    "#query=f\"\"\" select * from \"{database}\" \"\"\"\n",
    "#query=f\"\"\"SELECT * FROM \\\"cpptest\\\".\\\"autogen\\\".\\\"601318.SH\\\"  where time >= '2019-09-24T09:00:00Z' and time < '2019-09-24T16:00:00Z' order by time \"\"\"\n",
    "#query=f\"\"\"SELECT \\\"stkcd\\\",  \\\"cp\\\", \\\"OPNPRC\\\",\\\"PRECLOSE\\\", \\\"HighLimit\\\",\\\"LowLimit\\\",\\\"hp\\\",\\\"lp\\\",\\\"ts\\\",\\\"tt\\\", \\\"B1\\\",\\\"B2\\\",\\\"B3\\\",\\\"B4\\\",\\\"B5\\\",\\\"B6\\\",\\\"B7\\\",\\\"B8\\\",\\\"B9\\\",\\\"B10\\\",\\\"BV1\\\",\\\"BV2\\\",\\\"BV3\\\",\\\"BV4\\\",\\\"BV5\\\",\\\"BV6\\\",\\\"BV7\\\",\\\"BV8\\\",\\\"BV9\\\",\\\"BV10\\\",\\\"S1\\\", \\\"S2\\\",\\\"S3\\\",\\\"S4\\\",\\\"S5\\\",\\\"S6\\\",\\\"S7\\\",\\\"S8\\\",\\\"S9\\\",\\\"S10\\\",\\\"SV1\\\",\\\"SV2\\\",\\\"SV3\\\",\\\"SV4\\\",\\\"SV5\\\",\\\"SV6\\\",\\\"SV7\\\",\\\"SV8\\\",\\\"SV9\\\" ,\\\"SV10\\\" FROM \\\"cpptest\\\".\\\"autogen\\\".\\\"{measure}\\\"  where time >= '2019-09-24T09:00:00Z' and time < '2019-09-24T16:00:00Z' order by time \"\"\"\n",
    "                         \n",
    "result=client.query(query)\n",
    "if result!={}:\n",
    "    data=pd.DataFrame(result[measure])\n",
    "else:\n",
    "    data=pd.DataFrame()\n",
    "data"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {
    "scrolled": true
   },
   "outputs": [],
   "source": [
    "data.iloc[-40]\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "pd.set_option('display.max_rows',1000)\n",
    "data.shape\n",
    "\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "database='order'\n",
    "#client.drop_database(database)\n",
    "#client.create_database(database)\n",
    "#client = influxdb.DataFrameClient(host='192.168.38.152', port='8086', username='root', password='root', database='')\n",
    "measure='order'\n",
    "date=20200106\n",
    "b = dtparser.parse(str(date))+ datetime.timedelta(hours=0)\n",
    "e = dtparser.parse(str(date)) + datetime.timedelta(hours=24)\n",
    "query=f\"\"\" select * from \"{database}\".\"autogen\".\"{measure}\" where time >= {int(b.timestamp() * 1000 * 1000 * 1000)} and time < {int(e.timestamp() * 1000 * 1000* 1000)} \"\"\"\n",
    "#query=f\"\"\" select * from \"{database}\" \"\"\"\n",
    "#query=f\"\"\"SELECT * FROM \\\"cpptest\\\".\\\"autogen\\\".\\\"601318.SH\\\"  where time >= '2019-09-24T09:00:00Z' and time < '2019-09-24T16:00:00Z' order by time \"\"\"\n",
    "#query=f\"\"\"SELECT \\\"stkcd\\\",  \\\"cp\\\", \\\"OPNPRC\\\",\\\"PRECLOSE\\\", \\\"HighLimit\\\",\\\"LowLimit\\\",\\\"hp\\\",\\\"lp\\\",\\\"ts\\\",\\\"tt\\\", \\\"B1\\\",\\\"B2\\\",\\\"B3\\\",\\\"B4\\\",\\\"B5\\\",\\\"B6\\\",\\\"B7\\\",\\\"B8\\\",\\\"B9\\\",\\\"B10\\\",\\\"BV1\\\",\\\"BV2\\\",\\\"BV3\\\",\\\"BV4\\\",\\\"BV5\\\",\\\"BV6\\\",\\\"BV7\\\",\\\"BV8\\\",\\\"BV9\\\",\\\"BV10\\\",\\\"S1\\\", \\\"S2\\\",\\\"S3\\\",\\\"S4\\\",\\\"S5\\\",\\\"S6\\\",\\\"S7\\\",\\\"S8\\\",\\\"S9\\\",\\\"S10\\\",\\\"SV1\\\",\\\"SV2\\\",\\\"SV3\\\",\\\"SV4\\\",\\\"SV5\\\",\\\"SV6\\\",\\\"SV7\\\",\\\"SV8\\\",\\\"SV9\\\" ,\\\"SV10\\\" FROM \\\"cpptest\\\".\\\"autogen\\\".\\\"{measure}\\\"  where time >= '2019-09-24T09:00:00Z' and time < '2019-09-24T16:00:00Z' order by time \"\"\"\n",
    "                         \n",
    "result=client.query(query)\n",
    "if result!={}:\n",
    "    data=pd.DataFrame(result[measure])\n",
    "else:\n",
    "    data=pd.DataFrame()\n",
    "data"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "dd=data[data['filledVol']<data['placeVol']]\n",
    "s=list(dd['code'].unique())\n",
    "d=data[data['code'].isin(s)]\n",
    "d.sort_values(['code','ttime'])"
   ]
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python 3",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.8.8"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 4
}
